package com.jt.controller;



import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


//@RestController  使用此注解，程序将不会执行视图解析器的配置
@Controller
public class UserController {
    @Autowired
    private UserService userService;
@RequestMapping("/findAll")
public String findAll(Model model){
    System.out.println(123);
List<User> userlist=userService.findAll();
model.addAttribute("userList", userlist);
    return "userList";
}

//跳转到ajax.jsp页面中
    @RequestMapping("toAjax")
    public String toAjax(){
    return "ajax";
    }

/*
接收ajax请求：/findAjax
返回值：List<User>
 */
  @RequestMapping("/findAjax")
  @ResponseBody    //1.将返回值结果转化为JSON数据返回  2.代表ajax请求结束
    public List<User> findAjax(){

    return  userService.findAll();
    }
}
